package com.itcast.solr.dao;

import com.itcast.solr.pojo.TbItem;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.solr.core.query.result.HighlightPage;
import org.springframework.data.solr.repository.Highlight;
import org.springframework.data.solr.repository.Query;
import org.springframework.data.solr.repository.SolrCrudRepository;

import java.util.List;

public interface ItemSolrDao extends SolrCrudRepository<TbItem,Long>{

    /**
     * 根据标题查询所有符合条件的数据
     * @param title
     * @return
     */
    public List<TbItem> findByTitle(String title);


    /**根据多个条件进行查询
     *
     * @param title
     * @param min
     * @param max
     * @return
     */
    public List<TbItem> findByTitleAndPriceBetween(String title,double min,double max);
    /**
     * 查询满足条件的前10 的数据
     * @param title
     * @return
     */

    public List<TbItem> findTop10ByTitle(String title);

    /**
     * 查询满足条件的数据并进行排序
     * @param title
     * @param sort
     * @return
     */
    public List<TbItem> findTop10ByTitle(String title, Sort sort);

    /**
     * 以命名规范方式，进行区间查询
     * @param min
     * @param max
     * @return
     */
    public List<TbItem> findByPriceBetween(double min,double max);

    /**
     * 根据 标题
     * @param title
     * @return
     */
    public List<TbItem> findByTitleOrderByIdDesc(String title);

    /**
     * 自定义查询语句进行 查询
     * @param min
     * @param max
     * @return
     */
    @Query(value = "*:*",filters = {"item_price:[?0 TO ?1]"})
    public List<TbItem> selectListByPrices(double min,double max);
    /**
     * 查询结果，返回指定的字段的值
     * @param min
     * @param max
     * @return
     */
    @Query(value = "*:*",fields = {"item_title","item_price"},filters = {"item_price:[?0 TO ?1]"})
    public List<TbItem> selectListByPricesByMyColumn(double min,double max);

    /* ************************* 分页查询和高亮显示查询 **************************** */
    public Page<TbItem> findByTitle(String title, Pageable pageable);



    @Highlight(prefix = "<b style='color:red'>",postfix = "</b>")
    public HighlightPage<TbItem> findHighLightByTitle(String title,Pageable pageable);

//    @Highlight(prefix = "<b style='color:red'>",postfix = "</b>")
//    public HighlightPage<TbItem> findHighLightByTitleAndFilter(String title, FilterQuery filterQuery,Pageable pageable);

}
